package com.longjianghuasheng.logistics.business.inquiry

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.map
import com.longjianghuasheng.logistics.base.BaseMultiStateViewModel
import com.longjianghuasheng.logistics.business.home.ServiceType
import com.longjianghuasheng.logistics.business.inquiry.InquiryFragment.Companion.KEY_SERVICE1
import com.longjianghuasheng.logistics.repository.request.HttpRequestCoroutine

class ServiceSelectionViewModel : BaseMultiStateViewModel() {


    var type = ""

    val result1 by lazy {
        MutableLiveData<ServiceType>()
    }

    val convertResult = result1.map {

        val list = it.data?.map {

            FirstNode(
                it.title,

                it.types.map {
                    SecondNode(
                        it.title, it.types.map {

                            ThirdNode(it.title, it.id)

                        }.toMutableList()

                    ).apply {
                        isExpanded = false
                    }
                }.toMutableList()
            ).apply {
                isExpanded = false

            }

        }?.toMutableList()

        list?.removeLast()


        if (type == KEY_SERVICE1)
            list?.filter { it.title == "报关报检" }
        else
            list


    }

    fun service_list() {
        getData2({ HttpRequestCoroutine.service_list() }, result1)
    }

}